﻿using System.Collections;

namespace StaticProxyPattern;
/// <summary>
/// aop静态代理模式  简化接口实现成本
/// </summary>
public class StaticProxyPatternClass
{
    public static void testMain()
    { 
        var target = new Water(); 
        var proxy1 = new WaterProxy1(target);
        var proxy2 = new WaterProxy2(proxy1);
        proxy2.Invoke();


    }   
}
public interface IWater
{
    void Invoke();
}
public class Water: IWater
{
    public void Invoke()
    {
        Console.WriteLine("净化水资源");
    }
}


public class WaterProxy1 : IWater
{
    private readonly IWater _target;

    public WaterProxy1(IWater target)
    {
        _target = target;
    }

    public void Invoke()
    {
        Console.WriteLine("AOP净化水--111");
        _target.Invoke();
        Console.WriteLine("AOP净化水--222");
    }
}
public class WaterProxy2 : IWater
{
    private readonly IWater _target;

    public WaterProxy2(IWater target)
    {
        _target = target;
    }

    public void Invoke()
    {
        Console.WriteLine("AOP净化水--33333");
        _target.Invoke();
        Console.WriteLine("AOP净化水--44444");
    }
}
